<?php

include_once "config/Config.php";

include_once "model/dao/GenericDao.php";
include_once "model/bean/Account.php";

class AccountDao extends GenericDao {
	public function __construct($dsn, $username, $password) {
		parent::__construct($dsn, $username, $password);
			
		$this->mapping = new Mapping("Account", "MONEY_ACCOUNT", "id",
		array("id", "type", "category", "date", "amount", "tag", "description", "detail"),
		array("ACCOUNT_ID", "ACCOUNT_TYPE", "ACCOUNT_CATEGORY", "ACCOUNT_DATE", "ACCOUNT_AMOUNT", "ACCOUNT_TAG", "ACCOUNT_DESCRIPTION", "ACCOUNT_DETAIL"));
	}

	public function selectCategory($type) {
		$type = $type ? $type : "in";
		$tableName = $this->mapping->getTableName();
		$query = "SELECT DISTINCT(ACCOUNT_CATEGORY) AS category FROM " . $tableName . " WHERE ACCOUNT_TYPE='" . $type . "';";

		return $this->execute($query);
	}
}

?>